package wangxiaotao.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;
import wangxiaotao.aop.annotation.Log;
import wangxiaotao.bean.vo.RoomTypeSelectorVO;
import wangxiaotao.bean.vo.RoomTypeVO;
import wangxiaotao.common.CommonResult;
import wangxiaotao.converter.RoomTypeConverter;
import wangxiaotao.entity.RoomType;
import wangxiaotao.mapper.AdminMapper;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/roomType")
public class RoomTypeController extends BaseController{
    private final AdminMapper adminMapper;
    private final RoomTypeConverter roomTypeConverter;



    /**
     * 按照房间类型 获取该类型所有的房间
     * @param RoomType
     * @return
     */
//    @RequiresAuthentication
//    @GetMapping("/getAllRoomByRoomType/{RoomType}")
//    @Log
//    public CommonResult getAllRoomByRoomType(@PathVariable String RoomType){
//        return CommonResult.success(adminMapper.queryAllRoomType());
//    }

    /**
     * 根据 id room_type_no和room_bed获取数据
     * 在用户下单时获取对应的房间信息
     * @param id
     * @return
     */
    @RequiresAuthentication
    @GetMapping("/getRoomTypeByIdAndTypeNo")
    @Log
    public CommonResult getRoomTypeByIdAndTypeNo(@RequestParam String id,@RequestParam String typeNo){
        QueryWrapper<RoomType> wrapper = new QueryWrapper<>();
        wrapper.eq("room_type_no",typeNo).eq("id",id);
        return CommonResult.success(roomTypeConverter.toRoomTypeVO(roomTypeService.getOne(wrapper)));
    }

    /**
     * 获取所有的房间类型 id, 名称-床型
     * @return
     */
    @RequiresAuthentication
    @GetMapping("/getRoomTypeAndBed")
    @Log
    public CommonResult getRoomTypeAndBed(){
        QueryWrapper<RoomType> wrapper = new QueryWrapper<>();
        wrapper.select("id","CONCAT(room_type,'-',room_bed) as roomInfo");
        return CommonResult.success(roomTypeService.listMaps(wrapper));
    }

    /**
     * 根据房间id获取 对应的房间类型信息
     * @param roomId
     * @return
     */
    @RequiresAuthentication
    @GetMapping("/getRoomTypeByRoomId/{roomId}")
    public CommonResult getRoomTypeByRoomId(@PathVariable String roomId){
        RoomTypeVO roomTypeVO = roomTypeConverter.toRoomTypeVO(roomTypeService.getById(roomId));
        return CommonResult.success(roomTypeVO);
    }


    /**
     * 获取房间类型数据 在新增房间时选择房间类数据
     * @return
     */
    @RequiresAuthentication
    @GetMapping("/getSelectDataForRoomType")
    public CommonResult getRoomTypeForSelector(){
        List<RoomTypeSelectorVO> s = adminMapper.queryRoomTypeForSelector();
        return CommonResult.success(s);
    }
}
